package com.norra.client.ui

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import com.norra.client.R

open class BaseActivity : AppCompatActivity() {
    private var loadingView: LoadingView? = null

    fun showLoadingView() {
        if (loadingView == null) {
            loadingView = LoadingView(this)
        }

        if (!loadingView!!.isShowing) {
            loadingView!!.show()
        }
    }

    fun hideLoadingView() {
        if (loadingView != null && loadingView!!.isShowing) {
            loadingView!!.dismiss()
            loadingView = null
        }
    }

    fun startActivity(cls: Class<*>) {
        val intent = Intent(this, cls)
        startActivity(intent)
    }

    fun startActivityForResult(cls: Class<*>, requestCode:Int) {
        val intent = Intent(this, cls)
        startActivityForResult(intent, requestCode)
    }

    fun setUpToolBar() {
        val toolbar = findViewById<Toolbar>(R.id.toolbar)
        if (toolbar != null) {
            setSupportActionBar(toolbar)
            supportActionBar!!.setDisplayHomeAsUpEnabled(true)
            toolbar.setNavigationOnClickListener { onBackPressed() }

            supportActionBar!!.title = ""
        }
    }
}